package cn.platform.service.impl;

import cn.platform.entity.HarmonyChildMessage;
import cn.platform.entity.Student;
import cn.platform.mapper.HarmonyChildMapper;
import cn.platform.response.AResponse;
import cn.platform.service.HarmonyChildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Year;
import java.util.List;

@Service
public class HarmonyChildServiceImpl implements HarmonyChildService {
    @Autowired
    private HarmonyChildMapper harmonyChildMapper;

    /**
     * 根据学生id查询学生信息
     *
     * @param id 学生id
     * @return AResponse res 学生的信息
     *
     * @author jyz
     */
    @Override
    public AResponse getRoleMessage(Integer id){
        AResponse res = new AResponse();
        // 通过年份相减计算年级
        List<HarmonyChildMessage> students = harmonyChildMapper.getRoleMessage(id);
        for (HarmonyChildMessage student: students){
            student.setGrade(String.valueOf(Year.now().getValue() - Integer.parseInt(student.getGrade()) + 1));
        }
        res.setData(students);
        return res;
    }
}
